﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;

public partial class Login : System.Web.UI.Page
{
    public static String Nick = "";

    
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void txtName_TextChanged1(object sender, EventArgs e)
    {

    }

    protected void txtPassword_TextChanged1(object sender, EventArgs e)
    {

    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string str = ("Server=(local);Integrated Security=SSPI;database=Pets");
        SqlConnection connect = new SqlConnection(str);
        string UserID = txtID.Text;
        string Password = txtPassword.Text;


        string sql = "select * from [User] where UserID = '" + UserID + "' and Password = '" + Password + "'";
        SqlCommand command = new SqlCommand(sql, connect);
        connect.Open();
        SqlDataReader reader = command.ExecuteReader();
        reader.Read();
       

        if (reader.HasRows)
        {
            Nick = reader.GetValue(0).ToString().Trim();
            HttpCookie cookie = new HttpCookie("username");
            cookie.Value = HttpUtility.UrlEncode(Nick);
            Response.AppendCookie(cookie);
            Response.Redirect("index.html", true);
        }
        else
        {
            MessageBox.Show("对不起，你输入的账号或者密码错误！");

        }

        connect.Close();
    }



    protected void btnRegist_Click(object sender, EventArgs e)
    {
        Response.Redirect("regist.aspx", true);
    }

    protected void lnkReturn_Click1(object sender, EventArgs e)
    {
          Response.Redirect("index.html", true);
    }
}

   
